package com.yang.news.web.controller;

import com.yang.news.cache.hotSearch.HotSearchCache;
import com.yang.news.model.dto.HotSearchDTO;
import com.yang.news.model.dto.HotSearchDetailDTO;
import com.yang.news.model.page.Page;
import com.yang.news.service.HotSearchRecordService;
import com.yang.news.model.result.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 热搜查询
 * @author Billyang
 * @date 2024/9/12 20:55
 */
@RestController
@RequestMapping("/api/hotSearch")
public class HotSearchController {

    @Autowired
    private HotSearchRecordService hotSearchRecordService;

    @GetMapping("/queryByType")
    public ResultModel<HotSearchDetailDTO> queryByType(@RequestParam String type) {
        return ResultModel.success(HotSearchCache.CACHE_MAP.get(type.toUpperCase()));
    }

    @GetMapping("/pageQueryHotSearchByTitle")
    public ResultModel<Page<HotSearchDTO>> pageQueryHotSearchByTitle(@RequestParam(required = true) String title,
                                                                     @RequestParam(required = true) Integer pageNum,
                                                                     @RequestParam(required = true) Integer pageSize) {
        return ResultModel.success(hotSearchRecordService.pageQueryHotSearchByTitle(title, pageNum, pageSize));
    }
}
